<template>
  <div>
    <h1>我的申请</h1>
    <el-form :model="formInline" :rules="rules" ref="ruleForm" class="demo-form">
      <el-row>
        <el-col :span="6">
          <el-form-item label="请假人" label-width="80px">
            <el-input v-model="formInline.name" placeholder="请假人" disabled></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="6">
          <el-form-item label="请假开始时间" label-width="120px" prop="createTime">
            <el-date-picker
                v-model="formInline.createTime"
                type="datetime"
                placeholder="选择日期时间"
                align="right"
            ></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="请假结束时间" label-width="120px">
            <el-date-picker
                v-model="formInline.endTime"
                type="datetime"
                placeholder="选择日期时间"
                align="right"
            ></el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="6">
          <el-form-item label="请假天数" label-width="80px">
            <el-input-number v-model="formInline.days" :min="1" :max="10" label="请假天数"></el-input-number>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="请假类型" label-width="80px">
            <el-select v-model="formInline.type" placeholder="请选择">
              <el-option
                  v-for="item in leaveTypes"
                  :key="item.dictCode"
                  :label="item.dictLabel"
                  :value="item.dictCode">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>

        <el-col :span="6">
          <el-form-item label="班长审批" label-width="80px">
            <el-select v-model="formInline.banzhang" placeholder="请选择">
              <el-option
                  v-for="item in banzhangs"
                  :key="item.userId"
                  :label="item.userName"
                  :value="item.userId">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="请假原因" label-width="80px">
            <el-input
                type="textarea"
                :rows="2"
                placeholder="请输入请假原因"
                v-model="formInline.reason"
            ></el-input>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :offset="18" :span="6">
          <el-form-item>
            <el-button type="primary" @click="commit">提交</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>


  </div>
</template>

<script>
export default {
  name: "LeaveQJView",
  data() {
    var leaveTimeCheck = (rule, value, callback) => {
      if (new Date()> value) {
        callback(new Error('请假时间不能小于当前时间'));
      }
    };
    return {
      formInline:{
        name:"",
        createTime:"",
        days:null,
        type:null,
        reason:"",
        content:"",
        banzhangs:null,
      },
      rules: {
        createTime: [
          { validator: leaveTimeCheck, trigger: 'change' }
        ],
      },
      leaveTypes:[],
      banzhangs:[],

    }
  }, methods: {
    getLeaveType(){
      this.axios.post("/service/leaves/getLeaveType").then(res=>{
        this.leaveTypes=res.data.data;
        console.log(this.leaveTypes)
      })
    },
    getbanzhangs() {
      this.axios.post("/service/leaves/getBanzhang").then(res=>{
        this.banzhangs=res.data.data;
      })
    },
    getName() {
      this.axios.post("/service/leaves/getName").then(res=>{
        this.formInline.name=res.data.data;
      })
    },
    commit(){
      this.axios.post("/service/leaves/save",this.formInline).then(res=>{
        if (res.data.code==200){
          this.$message({
            message:'提交成功',
            type:'success'
          });
          this.formInline={};
        }else{
          this.$message({
            message:'提交失败',
            type:'error'
          });
        }
      })
    }
  }, created() {
    this.getLeaveType();
    this.getbanzhangs();
    this.getName();
  }
}
</script>

<style scoped>

</style>